<?php
/**
 * 树状图
 */
namespace Admin\Controller;

use Admin\Model\ArticleModel;
use Admin\Model\ColumnModel;
use Admin\Model\PageModel;
use Base\Controller\BaseAdminController;


/**
 * Class DetailController
 * @package Admin\Controller
 * 内容管理
 */
class DetailController extends BaseAdminController
{

    public function __construct()
    {
        parent::__construct();
    }

    /**
     * @param string $act
     * @param int $id
     */
    public function showList($act = '', $id = 0)
    {
        switch ($act) {
            case 'getTree':
                $columnModel = new ColumnModel();
                $list = $columnModel->field('id,model_id,title,column_id')->relation('model')->where('status=1')->select();
                foreach ($list as $k => $v) {
                    $list[$k]['title'] = $v['title'] . '(' . $v['model']['title'] . ')';
                }
                $this->ajaxReturn($list);
                break;
            case 'default':
                break;
            case 'show':
                $this->actionShow($id);
                break;
            default:
                $this->show('');
                break;
        }
    }

    private function actionShow($id, $act = '')
    {
        $columnModel = new ColumnModel();
        $column = $columnModel->getOne($id);
        $this->assign('column', $column);
//        $this->assign('$model_id',$column['model_id']);
        switch ($column['model_id']) {
            case 2:
                //文章
                $model = new ArticleModel();
                $map['status']=1;
                $map['column_id']=$id;
                $page = $model->pageToView(20, true, $map);
                $this->assign('list', $page['list']);
                $this->assign('page', $page['page']);
                $this->display('Article_showList');
                break;
            case 3:
                //单页
                $model = new PageModel();
                $data = $model->where('status=1 and column_id=%d', array($id))->find();
                $this->assign('data', $data);
                $this->display('Page_showEdit');
                break;
        }
    }
}